package org.fao.pims.web.references;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class ReferencesForm extends ActionForm {

	//input attributes
	private String plantName;
	private String animalName;
	private String authorName;
	
	public String getPlantName() {
		return plantName;
	}
	
	public void setPlantName(String plantName) {
		this.plantName = plantName;
	}
	
	public String getAnimalName() {
		return animalName;
	}
	
	public void setAnimalName(String animalName) {
		this.animalName = animalName;
	}
	
	public String getAuthorName() {
		return authorName;
	}
	
	public void setAuthorName(String authorName) {
		this.authorName = authorName;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request)
	{
		plantName = null;
		animalName = null;
		authorName = null;
	}

	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
	{
		ActionErrors errors = new ActionErrors();

		if( ((plantName == null) || plantName.trim().equals("")) &&
			((animalName == null) || animalName.trim().equals("")) &&	
			((authorName == null) || authorName.trim().equals("")) )
		{
			errors.add("queryParams", new ActionMessage("references.queryParams.blank"));
		}
		
		return errors;
	}
	
}
